<div id="headerPage">
    <span>Editar Permissões</span>
</div>
<div style="text-align:left;" id="box"> 
    <span style="margin-left:25.5%;"><b>Usuário:</b> <?php echo $usuario['nome_usuario']; ?></span>
    <form action="" method="POST" style="text-align: center">
    <table style="margin-top:10px;"class="table" align="center" frame="box" cellpadding="3">
        <thead>
            <tr>
                <th> ----- </th>
    <?php       foreach ($permissoes as $permissao){
                    echo "<th>{$permissao}</th>";
                } 
    ?>
            </tr>
        </thead>
        <tbody align="center">
            <?php $i = 0;
            //var_dump($modulos_permissoes);
            foreach ($modulos as $modulo){  
            $color = ($i % 2) == 0 ? 'par' : 'impar';
            $i++;
                ?>
            
            <tr class="<?php echo $color?>">
                <td align="left"><?php echo $modulo; ?></td>
                <?php foreach ($permissoes as $permissao){?>

            <?php 
            include_once 'app.functions/index_of.php';
            if (in_array($permissao, $modulos_permissoes[$modulo])){
                        $input = '<input type="checkbox" name="p['.index_of($permissao,$modulos_permissoes[$modulo]).']" ';
                        if (isset($usuario_permissoes[$modulo])){
                            if (in_array($permissao,$usuario_permissoes[$modulo])){ 
                                $input.='checked'; 
                            }
                        }
                        $input.=' />';
                }else{
                    $input = '----';
                }
            ?>

                <td><?php echo $input ?></td>
            <?php } ?>
            </tr>
            <?php } ?>
        </tbody>

    </table>
    <input style="margin-top:15px;" type="submit" value="Alterar" name="save" />
    <input type="button" value="Voltar" onclick="javascript:location='index.php?modulo=usuarios&page=visualizar'"/>
    </form>
</div>
